import {useRoutes} from "react-router-dom";
import {lazy} from "react";
// 代码分隔
const Dict = lazy(() => import("../pages/Dict"));
const User = lazy(() => import("../pages/User"));
const Literature = lazy(() => import("../pages/Literature"));
const Region = lazy(() => import("../pages/Region"));
const Article = lazy(() => import("../pages/Article"));
const FormLiterature = lazy(() => import("../pages/Literature/child/FormLiterature"));
const FormArticle = lazy(() => import("../pages/Article/child/FormArticle"));
const Home = lazy(() => import("../pages/Home"));

const Router = () => {
    return useRoutes([
        {
            path: "/home",
            element: <Home/>
        },
        {
            path: "/dict",
            element: <Dict/>
        },
        {
            path: "/user",
            element: <User/>
        },
        // 因为在app.tsx已经写了头部和子菜单作为公共部门，也就不需要写了
        {
            path: "/literature",
            children: [
                {
                    path: ":id",
                    element: <Literature/>,
                },
                {
                    // 这个id为分类id
                    path: "create/:id",
                    element: <FormLiterature/>
                },
                {
                    // 这个id为文献详情id
                    path: "update/:id",
                    element: <FormLiterature/>
                }
            ]
        },
        {
            path: "/region/:id",
            element: <Region/>,
            children: []
        },
        {
            path: "/article",
            children: [
                {
                    // 这个id为数据字典分类id
                    path: ":id",
                    element: <Article/>
                },
                {
                    // 这个id为分类id
                    path: "create/:id",
                    element: <FormArticle/>
                },
                {
                    // 这个id为文献详情id
                    path: "update/:id",
                    element: <FormArticle/>
                }
            ]
        },
        {
            path: "/*",
            element: <h1 style={{textAlign: "center"}}>404不存在</h1>
        }
    ]);
}

export default Router;